--步以量计
local buyiliangji = fk.CreateSkill {
    name = "mcdh_buyiliangji",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

buyiliangji:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
            return player:hasSkill(self) and target.phase == Player.Play and target ~= player and not player:isNude() and player:usedSkillTimes(self.name,Player.HistoryRound) == 0
    end,
    on_cost = function(self, event, target, player, data)
        local room =player.room
            local card = room:askForDiscard(player,1,1,true,self.name,true,".","#buyiliangji-discard:"..target.id,true)
            if #card > 0 then
                self.cost_data = card
                return true
            end
    end,
    on_use =  function(self, event, target, player, data)
        local room = player.room
            local card = Fk:getCardById(self.cost_data[1])
            local number = card:getNumberStr()
            room:throwCard(self.cost_data,self.name,player,player)
            target:drawCards(3,self.name)
            room:setPlayerMark(target,"@buyiliangji-phase",number)
    end
})

buyiliangji:addEffect(fk.EventPhaseEnd,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
            if  player:getMark("@buyiliangji-phase") ~= 0 and  player.phase == Player.Play and target == player then
                local events = room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                    local use = e.data[1]
                    if use.from == player.id and use.card:getNumberStr() == player:getMark("@buyiliangji-phase") then
                        return true
                    end
                end, Player.HistoryPhase)
                if #events == 0 then
                    return true
                end
            end
    end,
    on_cost = function(self, event, target, player, data)
            return true
    end,
    on_use =  function(self, event, target, player, data)
        local room = player.room
        room:askForDiscard(player,2,2,true,self.name,false,".","#buyiliangji_other-discard")
    end
})

Fk:loadTranslationTable{
    ["mcdh_buyiliangji"] ="步以量计",
    [":mcdh_buyiliangji"]="每轮限一次,每名其他角色的出牌阶段开始时,你可以弃置一张牌,令其摸三张牌,若如此做,出牌阶段结束时,若其本阶段未使用过与你弃置牌点数相同的牌，其弃置两张牌。",
    ["@buyiliangji-phase"] = "步以量计",
    ["#buyiliangji-discard"] ="步以量计:弃置一张牌,令 %src 摸三张牌",
    ["#buyiliangji_other-discard"] = "步以量计:弃置两张牌",
}

return buyiliangji